package ar.edu.uba.fi.jmit.monitorengine.backend.server;

import java.util.List;

import ar.edu.uba.fi.jmit.integrationcommons.Event;
import ar.edu.uba.fi.jmit.integrationcommons.EventPriority;
import ar.edu.uba.fi.jmit.monitorengine.MonitorEngineTestCase;
import ar.edu.uba.fi.jmit.monitorengine.backend.shared.dto.EventDTO;
import ar.edu.uba.fi.jmit.monitorengine.core.EventServiceManager;

public class EventServiceTestCase extends MonitorEngineTestCase {

	private EventServiceImpl service;
	
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		service = new EventServiceImpl();
		for (int index = 1; index <= 10; index++) {
			Event event = new Event();
			event.setPriority(EventPriority.NORMAL);
			event.setSource("EventSource" + index);
			EventServiceManager.getInstance().onRecivedEvent(event);
		}		
	}
	
	@Override
	protected void tearDown() throws Exception {
		EventServiceManager.getInstance().cleanEvents();
	}
	
	public void testEventService() {
		List<EventDTO> list = service.getLastRecivedEvents(0, 10);
		assertEquals(10, list.size());
		list = service.getLastRecivedEvents(0, 5);
		assertEquals(5, list.size());
		list = service.getLastRecivedEvents(6, 11);
		assertEquals(4, list.size());
		list = service.getLastRecivedEvents(10, 20);
		assertEquals(0, list.size());
		assertEquals(10, service.getReceivedEventsCount());
	}
	
	
}
